{% extends 'temp/index.html' %}
{% load kingadmin_tags %}

{% block  right-content-container %}
<h2 class="page-header">{{ appname }} -- {{ model_name }}</h2>

<div>
      <form>
            <input type="search" name="_q" value="{{ admin_class.search_fieldd }}">
            <input type="submit" value="Search">
        </form>


        <div>
            <form>

                {% for filter_column in admin_class.list_filter %}
                   {% build_filter_ele filter_column admin_class %}
                {% endfor %}

                <input type="submit" value="过滤">
            </form>

        </div>
        <div>
            <form method="POST" onsubmit="return build_action(this)">
                <div class="row">
                    <div class="col-md-2">
                        <select class="form-control" name="action">
                            <option value="">------------------</option>
                            {% for action in admin_class.actions %}
                            <option value="{{ action }}">{{ action }}</option>
                            {% endfor %}
                        </select>
                    </div>
                    <input type="submit" value="GO" class="btn btn-danger">
                </div>

            </form>
        </div>

        <table class="table table-striped">
            <thead>
                <tr>
                    <th ><input type="checkbox" onclick="choices_all(this)"></th>
                    {% for column in admin_class.list_display %}
                        <th><a href="?_o={% order_tag forloop.counter0 admin_class %}">{{ column }}{% sort_tag admin_class forloop.counter0 %}</a></th>
                    {% endfor %}
                </tr>
            </thead>
            <tbody>
                {% for obj in querysets %}
                    <tr><td><input type="checkbox" choices="true"></td>{%  build_table_row obj admin_class %}</tr>
                {% endfor %}
            </tbody>


        </table>


        <div>
            {% page admin_class querysets %}
        </div>


</div>
<script>
    function choices_all(ths){
        if ($(ths).prop('checked')){
            $('input[choices]').prop('checked',true)
        }else {
            $('input[choices]').prop('checked',false)
        }
    }

    function build_action(ths){
        var checked_eml = $('input[choices]').filter(':checked');
        var action_list = [];
        $.each(checked_eml,function(){
            var eml_id = $(this).parent().next().children().text();
            action_list.push(eml_id)
        });
        var action_list=JSON.stringify(action_list);
{#        var hidden_input = '<input type="hidden" name="actions_list" value=" '+ action_list + '"' + '>';#}
         var hidden_input = '<input type="hidden" name="actions_list" value='+action_list+'>'
        $(ths).prepend(hidden_input);
        console.log(hidden_input);
    }
</script>
{% endblock %}
